package com.deng.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Types;



public class Test1{
	
	private final static String _URL = "jdbc:sqlserver://localhost:1433";
	private final static String _DB_NAME = "ybkz";
	private final static String _DB_USER = "performance";
	private final static String _DB_PW = "performance";
	/**
	 * @param args
	 */
	public static void main(String s[]) {
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Connection conn=DriverManager.getConnection(_URL+";DatabaseName="+_DB_NAME,_DB_USER,_DB_PW);
	            if(conn != null){  
//	            	String sql  = "alter FUNCTION testFun\r(\r\t@abc int\r\t) RETURNS int  as BEGIN return 1 END";
	            	String sql =  "select * from DICT_USER";
//	            	System.out.println("::::updateData:::::   "+sql);		
	        		PreparedStatement pstmt = null;
	        		try{
//	        			CallableStatement proc  = conn.prepareCall("{? = call SP_GetFullNameOrganization (?)}");
//	        			 proc.registerOutParameter(1, Types.REAL);
//	        			 proc.setInt(2, 1);
//	        	       
//
//	        	            
	        			pstmt = conn.prepareStatement(sql);
	        			ResultSet rs = pstmt.executeQuery();
	        			
//	        			ResultSet rs = proc.executeQuery();//取得结果集
		        	       while(rs.next()){
		        	    	   System.out.println(rs.getString(1));
		        	       }
	        		}catch(Exception ex){
	        			ex.printStackTrace();	
	        		}
//	                Statement statement = conn.createStatement();        
//	                ResultSet rs = statement.executeQuery("select * from sys.all_sql_modules where object_id  in (select id from sysObjects where type = 'FN' and name like 'FUN_%' )");        
//	                int c = rs.getMetaData().getColumnCount();        
//	                while(rs.next()){                           
//	                    System.out.println();        
//	                    for(int i=1;i<=c;i++){        
//	                        System.out.print(rs.getObject(i));        
//	                    }        
//	                }        
//	                rs.close();        
	            }        
	            
	            
	            
	            
	            
	            
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		 
	}
//		
//		// TODO Auto-generated method stub
////		ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
////		ImageIO.write((RenderedImage)image, image_format, bos); 
////		bos.toByteArray();
//		try{
//			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//			Connection con=DriverManager.
//			getConnection(_URL+";DatabaseName="+_DB_NAME,_DB_USER,_DB_PW);
//			
//			File f=new File("C:\\Users\\Deng\\Desktop\\68fa0919jw1dh3n1kmpwmj.jpg");
//		    int length=(int)f.length();
//		    InputStream fin=new FileInputStream(f);
//		    //SQL Server中只有image类型可以存储二进制数据
//		    PreparedStatement pstmt=con.prepareStatement("update wltjbg set xdt_img = ?");
//		    pstmt.setBinaryStream(1, fin, length);
//		    pstmt.executeUpdate();
//		    pstmt.clearParameters();
//		    pstmt.close();
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
//		
	
	

}
